package org.cytoscape.myapp.cytoscape_app_v1.internal.metrics.measure;

import java.util.ArrayList;
import java.util.List;

import org.cytoscape.myapp.cytoscape_app_v1.internal.metrics.domain.TrustedRelationship;
import org.cytoscape.myapp.cytoscape_app_v1.internal.metrics.domain.User;
import org.cytoscape.myapp.cytoscape_app_v1.internal.metrics.domain.UserPositionMapping;



public class SocialInfluence {

	private UserPositionMapping mapping;
	private StructuralCohesion structuralCohesion;
	private SocialSimilarity socialSimilarity;
	private SocialCentrality socialCentrality;

	public SocialInfluence(UserPositionMapping mapping, List<TrustedRelationship> trustedRelationships) {
		this.mapping=mapping;
		this.structuralCohesion=new StructuralCohesion(this.mapping,trustedRelationships);
		this.socialSimilarity=new SocialSimilarity(this.mapping);
		this.socialCentrality=new SocialCentrality(this.mapping);
	}

	/**
	 * Return the Social Influence Matrix
	 * @return double[][]
	 */
	public double[][] getSIMatrix(){
		double[][] stc=this.structuralCohesion.getStCMatrix();
		double[][] ss=this.socialSimilarity.getSSMatrix();
		double[] sc=this.socialCentrality.getSCVector();
		double[][] si=new double[this.mapping.getUsers().size()][this.mapping.getUsers().size()];
		List<User> usersList=new ArrayList<User>();
		usersList.addAll(this.mapping.getUsers().values());
		for (int i=0;i<usersList.size();i++) {
			String userId1=usersList.get(i).getId();
			for (int j=0;j<usersList.size();j++) {
				if(i!=j){
					String userId2=usersList.get(j).getId();
					int positionUser1=this.mapping.getPositionByUserId(userId1);
					int positionUser2=this.mapping.getPositionByUserId(userId2);
					si[i][j]=0.2*stc[positionUser1][positionUser2]+
							0.4*ss[positionUser1][positionUser2]+
							0.4*sc[positionUser1];
				}
			}
		}
		return si;
	}
}
